package mypackage.file;

import java.io.*;

public class Copy {
    public static void main(String[] args) {
        File pic1 = new File("C:/test1.jpg");
        File pic2 = new File("D:/test2.jpg");
        FileInputStream fis = null;
        FileOutputStream fos = null;
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            fis = new FileInputStream(pic1);
            fos = new FileOutputStream(pic2);
            bis = new BufferedInputStream(fis);
            bos = new BufferedOutputStream(fos);
            byte[] b = new byte[1024];
            while (bis.read(b) != -1) {
                bos.write(b);
            }
            bos.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.out.println("找不到文件");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("文件读取错误");
        } finally {
            try {
                if (bos != null) {
                    bos.close();
                }
                if (bis != null) {
                    bis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("关闭流出错");
            }
        }
        System.out.println("复制成功");
    }
}
